package com.ruoyi.web.controller.test;

import com.google.gson.Gson;
import com.ruoyi.web.controller.test.pojo.JsonRootBean;
import okhttp3.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class keyword {

    public static Gson gson=new Gson();

    public static void main(String[] args) throws Exception{


//        String[] keys={"standard size checkout counter","second hand supermarket racks"};
      String[] keys={"standard size checkout counter","second hand supermarket racks","fruit vegetable display rack","supermarket shopping basket","supermarket display freezer","SUPERMARKET CASHIER COUNTER","store supermarket supplies","5 gallon water bottle rack","supermarket rack in india","double sided display rack","SUPERMARKET SHOPPING CART","FRUIT AND VEGETABLE SHELF","commercial display shelf","FOLDING Shopping Trolley","trolley for supermarket","plastic shopping basket","metal supermarket shelf","plastic pallet prices","cashier counter table","retail display stand","metal shelving racks","cashier table design","bar counter for sale","Shelves for pharmacy","warehouse mezzanine","mini market shelves","grocery store shelf","gondolas for stores","furniture for store","wood display stand","retail store shelf","metal storage rack","warehouse racking","supermarket metal","children clothing","Shelf for storage","plastic tool box","fruit stand wood","boutique shelves","grocery shelves","folding trolley","floor mezzanine","display freezer","Store Furniture","store shelving","retail shelves","plastic basket","metal shelving","display fridge","COUNTER DESIGN","store display","stand display","shelf display","pharmacy rack","gondola store","boltless rack","Display store","shop shelves","rack storage","label holder","grocery rack","Market stand","plastic box","modern desk","wire shelf","steel rack","rack stand","metal rack","mart racks","superably","chip rack","CHECKOUT","go cart"};

        String key="shelf";


        List<String> ids= new ArrayList<>();

        for (String k:keys) {
            JsonRootBean json=getKey(k);
            ids.add(json.getData().get(0).getId()+"");
            System.out.println(json.getData().get(0).getKeyword() +"    -    "+json.getData().get(0).getId());
        }



        Map<String,String> maps=new HashMap<>();


        // in_promotion 启动   停止 stopped
        maps.put("cmd","stopped");
        maps.put("kwIds",ids.toString().replace("[","").replace("]","").replaceAll(" ",""));

        System.out.println(ids.toString());

        System.out.println(gson.toJson(maps));
        startStopKey(maps);


    }

    public static  void startStopKey (Map<String,String> maps) throws  Exception{
        System.out.println(gson.toJson(maps));
        OkHttpClient client = new OkHttpClient().newBuilder()
                .build();
        MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded; charset=UTF-8");
        RequestBody body = new MultipartBody.Builder().setType(MultipartBody.FORM)
                .addFormDataPart("json",gson.toJson(maps))
                .addFormDataPart("_dt_p4p_id_","0bb3d95716261596044092761e554e")
                .addFormDataPart("_csrf_token_","cfg9jow4won6")
                .addFormDataPart("_dt_page_id_","717788280b1da3a160ed39f417a9eaa651c69aa649")
                .build();
        Request request = new Request.Builder()
                .url("https://www2.alibaba.com/asyBatchStartOrStopKeywords.do?ctoken=mcvf7optu4w7&dmtrack_pageid=717788280b1da3a160ed39f417a9eaa651c69aa649")
                .method("POST", body)
                .addHeader("content-type", "application/x-www-form-urlencoded; charset=UTF-8")
                .addHeader("cookie", "ali_apache_id=11.177.40.123.1614923582281.176439.1; cna=l44uGGZ4UH8CAQ6RFXEyJu9n; father_noviceprompt_disable=true; father_movehint_disable=true; t=b16e266b75d3f33e801c9a0e479ce043; _bl_uid=tdkFRo5Oedm1hCbt2yv7k7dkCbgq; cbc=G77A702EDF359D1D62C9C808464134E98939A4297DA8B253405; umdata_=G2476875C7BC8BE6E363C76C39B6CF7CBDFADDABB671A5034F4; _ga_RVSKK1KF5N=GS1.1.1624421058.2.0.1624421058.60; history=company%5E%0A232047054%24%0A251367239%24%0A253923890%24%0A239890964; xman_us_f=x_locale=zh_CN&x_l=1&last_popup_time=1624151540118&x_user=CN|Da|Run|cgs|206025245&no_popup_today=n&acs_rt=772d02f46d054c7c821332caa58bc57e; __utma=226363722.1444323425.1615430544.1621995236.1624523801.9; __utmz=226363722.1624523801.9.9.utmcsr=message.alibaba.com|utmccn=(referral)|utmcmd=referral|utmcct=/feedbackset/basic.htm; sc_g_cfg_f=sc_b_currency=CNY&sc_b_locale=en_US&sc_b_site=CN; xlly_s=1; acs_usuc_t=acs_rt=62c50766d5754666a06dad8d33e27abd; cookie2=13e869ab1f19afc5e5f33ece7a8c0f58; _tb_token_=3e5e9957b9ee1; _samesite_flag_=true; _hvn_login=4; intl_locale=zh_CN; ali_apache_tracktmp=W_signed=Y; XSRF-TOKEN=899cbf67-c28a-4314-991e-230bbcea26c8; xman_us_t=ctoken=mcvf7optu4w7&l_source=alibaba&x_user=x8lfnjWwwgAoCY7iTuopxkSb5/h9Y1IXlvYqdeTHpg8=&x_lid=rundahj&sign=y&need_popup=y; intl_common_forever=UQVT1turJiAEnNH5Ds6DrF2CzrxsjvBt4+1cF9HHhPr6FHSZMA2gbw==; xman_f=rg4DQfdsa5MelC5tY5JGxZioCDZ/pcxHhYLjkql0CfRBWW/ltIbyhXYpiUdimu3IuxZi0nT2eNSXTX9AeVEHabstSyrDQfGpW75la0aPx8hR9a99Wm7lwu+ZntZZwF1Phoe7jEbngvn/watbH3bFFmbVq52itlI43SCO8YVHEmrQnnQS1dqbxrBycl7yJvEjcIJyjmqHBxph36cVE3WRA9YCMpWYEzS+GxTHpT5yImO29saCRlQRJe91GNxM748Lp+3feJA26ssnicZv+pNmw+T+r5p6ZXlABXvO5U4DqgQJQnfuesorCMsqmwC3Myv9fLtY2B/56EAcPQHHrLQK/a9694hj+EIbV1iXK7Ys8cYHMGAkEb99N/uUiS7OLz5HSMLRa46sr5E=; ali_apache_track=ms=|mt=3|mid=rundahj; _m_h5_tk=9ae310abbe09b2f249af6bf330b601d9_1626166505958; _m_h5_tk_enc=370c0054727d1659b541918deac37744; _ga=GA1.2.1444323425.1615430544; _gid=GA1.2.1490071414.1626156702; _m_h5_c=faf04acda5e7eac6ca5d3eafc3a1ec96_1626166622262%3Bf4f4859d3a7b8eeaedc1c70a0baea4bc; csg=09c0a2e3; JSESSIONID=A6238A6B17ADC6FA656A68DCAC469348; xman_t=wOz5DGDK8KJcJQplNyUVQEKb/1dT3CRl9KJjKQIKsFsJpsgWlXXtA/SdFYkjl1DppUjNsXV5gFaO6cB0jECpsnFz5XIoM9e4rD8YwiWBRi05R4pmrjIpFEWqWgZFiRaGjHh7T9cmfn++H5bqjQB67NsQHVVCCbjplF1aaWx6UsyRl7uMylFXXUSmc5t1hASlFLFrnBrAuv8g9xH3YZg5/O6IFxuzFw7kLh/+FemMcZcIV3LPYl0P9yV28BFrOMVNi6IaxD+xKTikKK+IXapKmL7YZA71ADwGpxi6xBfzQLQtz/K8++OaFMGKerkcROaWX9ZXic4fjP4v3o+6ZLNKzeO6MeQbLJB7wAQOje3gtWjq37QIarO/GLYaW7DE7lJ8IBCk6/BwO5bc36uccyc6X35UTa0AVDZD9uh5IwHdi4JwCKoN0vVftTBTJzzn3O0uhoKqNtZHwKMQ7D8zjd5cg9HLYZZUz7QYzRtpyQLnLva21sD5MJa5D1QWK5Qkb3DhRFL6gzjAG6KOE14eF5tfQVi+MLTQXDdBqPq67W8Gu5nOXc1uogaHlTj5nkStfmlmA9Hv/SNdbwqekO5jOVe7oTfR8PxmMAPtpQyYX0dMDDC8ZcBhUu6DNZoODFhpv/tPF3Qa63oVgW8B3MJFSZ9GjPBUEP9NhRRCkaPKvW/5zruGPZkvCHp95w==; tfstk=c46cBOvzEsRXF-AlO-9fm7IeB0uGarMw-OW5UOwQeBPwZfOJ0sc-aXPjDuYDqPG1.; l=eBOpgjV7O6f28rYUB91Bnurza77On7Ob8qZ0aNbMiIErm_5ZRtT6wHbOOH92d396cjWVMcYJ4ZpsfPyteFeL5PHXUkGuoeLNZGhkhFYN.; isg=BOjoW_UfHGbhNQ-o8pE5sR45udb6EUwb4xwmxqJaOmPY_ZJnQyP3qUR78ZUNTQTz; ali_apache_id=11.177.40.123.1611568794666.171275.2; ali_apache_track=ms=|mt=3|mid=rundahj; ali_apache_tracktmp=W_signed=Y; sc_g_cfg_f=sc_b_locale=en_US; t=2e4515c581dbf4498e55e535916b2626; xman_f=jtO4Xm6EV71y7tn0eEwcWtEfOF5PiJcHQ9Q/b4RQBQyBGDqll8DYgX7AehQG/9WombMFQvSFk4MZcOvNg4VSd2An7fhE943p5u6CSEQMhs6FTYzQLHJsqg==; xman_t=gkofZlq4i3Wq93FKSAooxzS4SxY7bIKWq0whX1Gc5h82SE7rgo/CqL9vBiR6L4sdYHP9gItMoopgUO55bjGfFIQ9XOe2hWLaSPgd3O5tGM6Wqovln+cSiLvI3JnlEFKUyEHA6eSbw9UozxozWAu7yFKDiKFKMPXBrJ7z/GVJDRsKbfpVWC0jF/8XorF7Q3l6+6BFR4oEDy1ZNE+NXqWUPq6t9JkJUiHXMPuH9q+qQVtaZs6vgbt/9kAL14sVJk1wAPvKXQDz9BCyaOflSaOnQ+dn5PPgbYfD5AhSPmMfmgnWCxP4e4FIo2cH4Vy0/Vcb5iQRi+TsTfDhl5O8grvjcTAXToyDJJ7nUHaAM0WCK1CKY81GtYSvZ+qLkAIB/bdyjkAhLdKI9lQ6oe3c+vagmOAtUI2Eso4BNSXH81P9gcmq7FrRAibretuZgvRKkafoUgd5TV4d9nq7zmxP2YuCHXDvbqmCgdX6Hl9siTSXO+js9mAYrJIoftptMA5Ykc5HkYgT5rHo4zctVhUEiUtlPktjW/GPkvN8Hs+lOEXmASE7KRAvgLfjgkvh2ysMzZd/8QcIdxOy8lIntQatf2IbPm0UxCjLI8KoV/Lvn119iYDo5W9ek/MJ+rLz/JyDsVnmSEryzuLymfy9QPbVcrktoJwob5gWEzDL03XTTYpoKvULZ7q7scmR+g==; xman_us_f=x_l=1; JSESSIONID=AF21EB062BC9D8F2332549B3D004F856")
                .addHeader("eagleeye-pappname", "iw0okbwm8i@b07e1e64c81f96b")
                .addHeader("eagleeye-sessionid", "CXkC2r0e1U1ems03UahCljLsXwhC")
                .addHeader("eagleeye-traceid", "477e49a3162614047062910161f96b")
                .addHeader("origin", "https://www2.alibaba.com")
                .addHeader("referer", "https://www2.alibaba.com/manage_ad_keyword.htm?spm=a27bb.base_report.bp_menu.d_keyword_promotion.126e3e5fM4OS10")
                .addHeader("sec-fetch-dest", "empty")
                .addHeader("sec-fetch-mode", "cors")
                .addHeader("sec-fetch-site", "same-origin")
                .addHeader("user-agent", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36")
                .addHeader("x-requested-with", "XMLHttpRequest")
                .build();
        Response response = client.newCall(request).execute();

        System.out.println(response.body().string());


    }

    public static JsonRootBean getKey(String key) throws Exception{


        OkHttpClient client = new OkHttpClient().newBuilder()
                .build();
        MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded; charset=UTF-8");
        RequestBody body = new MultipartBody.Builder().setType(MultipartBody.FORM)
                .addFormDataPart("json"," {\"status\":\"all\",\"cost\":\"all\",\"click\":\"all\",\"exposure\":\"all\",\"cpc\":\"all\",\"qsStar\":\"all\",\"kw\":\""+key+"\",\"isExact\":\"Y\",\"date\":7,\"tagId\":-1,\"delayShow\":false,\"recStrategy\":1,\"recType\":\"recommend\"}")
                .addFormDataPart("_dt_p4p_id_"," 0bb3d95716261596044092761e554e")
                .addFormDataPart("_csrf_token_"," cfg9jow4won6")
                .addFormDataPart("_dt_page_id_"," 717788280b1da3a160ed39f417a9eaa651c69aa649")
                .build();
        Request request = new Request.Builder()
                .url("https://www2.alibaba.com/asyGetAdKeyword.do?ctoken=mcvf7optu4w7&dmtrack_pageid=717788280b1da3a160ed39f417a9eaa651c69aa649")
                .method("POST", body)
                .addHeader("content-type", "application/x-www-form-urlencoded; charset=UTF-8")
                .addHeader("cookie", "ali_apache_id=11.177.40.123.1614923582281.176439.1; cna=l44uGGZ4UH8CAQ6RFXEyJu9n; t=b16e266b75d3f33e801c9a0e479ce043; cbc=G77A702EDF359D1D62C9C808464134E98939A4297DA8B253405; umdata_=G2476875C7BC8BE6E363C76C39B6CF7CBDFADDABB671A5034F4; _ga_RVSKK1KF5N=GS1.1.1624421058.2.0.1624421058.60; history=company%5E%0A232047054%24%0A251367239%24%0A253923890%24%0A239890964; xman_us_f=x_locale=zh_CN&x_l=1&last_popup_time=1624151540118&x_user=CN|Da|Run|cgs|206025245&no_popup_today=n&acs_rt=772d02f46d054c7c821332caa58bc57e; __utma=226363722.1444323425.1615430544.1621995236.1624523801.9; __utmz=226363722.1624523801.9.9.utmcsr=message.alibaba.com|utmccn=(referral)|utmcmd=referral|utmcct=/feedbackset/basic.htm; sc_g_cfg_f=sc_b_currency=CNY&sc_b_locale=en_US&sc_b_site=CN; xlly_s=1; acs_usuc_t=acs_rt=62c50766d5754666a06dad8d33e27abd; cookie2=13e869ab1f19afc5e5f33ece7a8c0f58; _tb_token_=3e5e9957b9ee1; _samesite_flag_=true; _hvn_login=4; intl_locale=zh_CN; ali_apache_tracktmp=W_signed=Y; _m_h5_c=9f666e904487667a7cba13eebbd927c0_1626156059546%3B0f58b6d95eb44cddf6e52e68af0206dd; xman_us_t=ctoken=mcvf7optu4w7&l_source=alibaba&x_user=x8lfnjWwwgAoCY7iTuopxkSb5/h9Y1IXlvYqdeTHpg8=&x_lid=rundahj&sign=y&need_popup=y; intl_common_forever=UQVT1turJiAEnNH5Ds6DrF2CzrxsjvBt4+1cF9HHhPr6FHSZMA2gbw==; xman_f=rg4DQfdsa5MelC5tY5JGxZioCDZ/pcxHhYLjkql0CfRBWW/ltIbyhXYpiUdimu3IuxZi0nT2eNSXTX9AeVEHabstSyrDQfGpW75la0aPx8hR9a99Wm7lwu+ZntZZwF1Phoe7jEbngvn/watbH3bFFmbVq52itlI43SCO8YVHEmrQnnQS1dqbxrBycl7yJvEjcIJyjmqHBxph36cVE3WRA9YCMpWYEzS+GxTHpT5yImO29saCRlQRJe91GNxM748Lp+3feJA26ssnicZv+pNmw+T+r5p6ZXlABXvO5U4DqgQJQnfuesorCMsqmwC3Myv9fLtY2B/56EAcPQHHrLQK/a9694hj+EIbV1iXK7Ys8cYHMGAkEb99N/uUiS7OLz5HSMLRa46sr5E=; ali_apache_track=ms=|mt=3|mid=rundahj; _m_h5_tk=9ae310abbe09b2f249af6bf330b601d9_1626166505958; _m_h5_tk_enc=370c0054727d1659b541918deac37744; _ga=GA1.2.1444323425.1615430544; _gid=GA1.2.1490071414.1626156702; csg=66e0554a; xman_t=aoHg9E3OuIqnqfuA1Bo7PByRNfdtpRl4HfPdl+tcN/GxE9QHYmmoNvQunsE5ENDFdaOwsJxbK4afOPVCE05W88oVyPMXxdvrljzKvJvuM1sLhh0rHBmsNDhORqRvck/toFGUrzmT0By++sqMvqqsCqQ9tghJ7gxnfuGk8sPcw+yT3xas3fjwGQyUhu4UZBNhFmjGuvHTiTN7K/bIz3G2HY7jEwAYyc3CvNePsImqKHI7Fo6le/moy5jIU5VXRDQfv9OP0r1uVT+BFqZlcwr1WxSe8TmPX6BNvy0nO3Wx86/cgFKAQBD09jDsiIOlBGIdAP8gvErCvjgWOPpUf9zbGpp2SZ+N0lh54wlqVCHJTvWXw2FfVSkioJagYA6LU8zyblgf/gNIF3+gWjhxYtGpCPnZK8yA6SP0ztdyH8iguerL/xg084vMCUUQN4/LEn9d5T+zNO0QbNpdLzK6R2Mj2VXaX6VbauLkyQHjyRMJ3Yq/daO5jtveOwNGvwH9g5oYVfnnR7Hwvs4c0bo9T8I+QoTcNIjUrFQ1F7mtFMZ1JvKopQtaWHZ/C5lDFXZL97hsoiKMyHKsn/3EuTXKcKrlFxwyoyZMUb9Je/jepm+yL1CDwaWsMCP1L24HWms4BAQO+kc+X55iEhwEKEQOt4iL3CwYsjs7Ogu/aj1+GeK3nVI17kbzUPNvhg==; isg=BJubrpTpf8-r5rxx3ZC6qLlIKv8FcK9yZO11f43abRqxbLtOFULAwlWtAsxizAdq; tfstk=cgEVB0MsgiIqgnn1JmiwCwPeGowAZ2w0I3kIozOC_tCCXVgciodtETOtUAaTQqf..; l=eBOpgjV7O6f2813iBO5aPurza77T3QAb4sPzaNbMiInca1PNOF17aNCBApvH5dtjgtCb5etPkdi_7RLHR3jR2xDDB8u_2D7-ExvO.; ali_apache_id=11.177.40.123.1611568794666.171275.2; ali_apache_track=ms=|mt=3|mid=rundahj; ali_apache_tracktmp=W_signed=Y; sc_g_cfg_f=sc_b_locale=en_US; t=2e4515c581dbf4498e55e535916b2626; xman_f=jtO4Xm6EV71y7tn0eEwcWtEfOF5PiJcHQ9Q/b4RQBQyBGDqll8DYgX7AehQG/9WombMFQvSFk4MZcOvNg4VSd2An7fhE943p5u6CSEQMhs6FTYzQLHJsqg==; xman_t=mH+DdDIuS6ngslE+2rUHuM9hT2YTq/nmZe19m+bDsQzS5PPfeCvoBQHX9dYhZLfuV98lKsCElFOMBBUmHm/IU4artr8FQQA57PraYuuVvuVUlQ2YHs3pL2t8KWMipUsyun0bNoxBcEu0aKyjZ/tIsTkBNyT2N/DlYL/8oXimnl9mFutIl0vetZveC33MrSRZNelxVBnn8jA8My+24gLTsWf+MAmQ2PJwNPR50aKz37QQFjvz4NiJQq+7dAC0uxnAX/KotpCnnhFzdYu6xWgARBfvmI4G3CFB9HtLJgiGPFWrzgm0gOFOzQwGdVXePfrrAytiMxYjflDa3f0G9Ai7mLVXQFWv7CCMMOIQOs+rZ2tyCwyEvmnSabYUNDqjEcoeF+RjauurDluJD5BWvSH4mvGE2KGQmT+3EgJfr3FOYkqHhzTFSgxoZJS/HAZD94IifE45Pg9lIncoza0vXUOthJLDyBaXUMm6K6JSkGa6Rg6dLFHznZsFjU2BTkmlkbEbmhwzp9lY9b8zgJOUSBTI3NP2/DD8Ry0Y4a3dC3ItCId3dwDO/vgSu5A+ruGp64xWvk0qA2qXSSTtlnrfGcSlhKBYcGCW7VEwbWyDaqjvgNQqZ9Qsapte5MyMR5x4TbRmcvZUKUyGZWxOE04cYPF4mHEgA0+C5/B1xTc0hV9Ug0EuWQlWfHukCA==; xman_us_f=x_l=1; JSESSIONID=84D4D524B0454E33E3D727D4B571799E")
                .addHeader("eagleeye-pappname", "iw0okbwm8i@b07e1e64c81f96b")
                .addHeader("eagleeye-sessionid", "CXkC2r0e1U1ems03UahCljLsXwhC")
                .addHeader("eagleeye-traceid", "477e49a3162614047062910161f96b")
                .addHeader("origin", "https://www2.alibaba.com")
                .addHeader("referer", "https://www2.alibaba.com/manage_ad_keyword.htm?spm=a27bb.base_report.bp_menu.d_keyword_promotion.126e3e5fM4OS10")
                .addHeader("sec-fetch-dest", "empty")
                .addHeader("sec-fetch-mode", "cors")
                .addHeader("sec-fetch-site", "same-origin")
                .addHeader("user-agent", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36")
                .addHeader("x-requested-with", "XMLHttpRequest")
                .build();
        Response response = client.newCall(request).execute();

        String json=response.body().string();


        JsonRootBean jsonr=gson.fromJson(json, JsonRootBean.class);

        return jsonr;

    }

}
